package cn.micai.base.io;

import java.io.File;

/**
 * 描述：How to make a file read only in java
 * <p>
 *
 * @author: 赵新国
 * @date: 2018/6/7 14:13
 */
public class FileHiddenMain {

    public static void main(String [] args) {
        System.out.println("-----------------");
        // Read the file
        File configFile = new File("src/main/resources/config.properties");
        configFile.setReadOnly();

        if (configFile.canWrite()) {
            System.out.println("Config file can be writtern");
        } else {
            System.out.println("config file is read only");
        }
        System.out.println("-----------------");

        System.out.println("Making config file writable again");
        // this method is available from jdk 1.6
        configFile.setWritable(true);

        if(configFile.canWrite()) {
            System.out.println("Config file can be written");
        } else {
            System.out.println("config file is read only");
        }
        System.out.println("-----------------");

    }
}
